/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.cs.mailbox.MailServiceException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class RecalculateMailboxCounts
/*     */   extends AdminDocumentHandler
/*     */ {
/*  39 */   private static final String[] TARGET_ACCOUNT_PATH = { "mbox", "id" };
/*     */   
/*     */ 
/*     */ 
/*     */   protected String[] getProxiedAccountPath()
/*     */   {
/*  45 */     return TARGET_ACCOUNT_PATH;
/*     */   }
/*     */   
/*     */   protected Element proxyIfNecessary(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  51 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  52 */     if (zsc.getProxyTarget() != null) {
/*  53 */       return null;
/*     */     }
/*     */     
/*  56 */     Provisioning prov = Provisioning.getInstance();
/*  57 */     String[] xpath = getProxiedAccountPath();
/*  58 */     String acctId = xpath != null ? getXPath(request, xpath) : null;
/*  59 */     if (acctId != null) {
/*  60 */       Account acct = getAccount(prov, Key.AccountBy.id, acctId, zsc.getAuthToken());
/*  61 */       if ((acct != null) && (!Provisioning.onLocalServer(acct))) {
/*  62 */         return proxyRequest(request, context, acctId);
/*     */       }
/*     */     }
/*  65 */     return null;
/*     */   }
/*     */   
/*     */   public boolean domainAuthSufficient(Map<String, Object> context)
/*     */   {
/*  70 */     return true;
/*     */   }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context) throws ServiceException
/*     */   {
/*  75 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*     */     
/*  77 */     Element mreq = request.getElement("mbox");
/*  78 */     String accountId = mreq.getAttribute("id");
/*     */     
/*  80 */     Provisioning prov = Provisioning.getInstance();
/*  81 */     Account account = prov.get(Key.AccountBy.id, accountId, zsc.getAuthToken());
/*  82 */     if (account == null) {
/*  83 */       throw AccountServiceException.NO_SUCH_ACCOUNT(accountId);
/*     */     }
/*  85 */     checkAdminLoginAsRight(zsc, prov, account);
/*     */     
/*  87 */     Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account, false);
/*  88 */     if (mbox == null) {
/*  89 */       throw MailServiceException.NO_SUCH_MBOX(accountId);
/*     */     }
/*     */     
/*  92 */     mbox.recalculateFolderAndTagCounts();
/*     */     
/*  94 */     Element response = zsc.createElement(AdminConstants.RECALCULATE_MAILBOX_COUNTS_RESPONSE);
/*  95 */     response.addElement("mbox").addAttribute("id", accountId).addAttribute("used", mbox.getSize());
/*     */     
/*     */ 
/*  98 */     return response;
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 103 */     relatedRights.add(Rights.Admin.R_adminLoginAs);
/* 104 */     relatedRights.add(Rights.Admin.R_adminLoginCalendarResourceAs);
/* 105 */     notes.add("If the target is an account, need the adminLoginAs right; If the target is a calendar resource, need the R_adminLoginCalendarResourceAs right.");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/RecalculateMailboxCounts.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */